Operators

Increment and decrement (++, --)

  • The increase operator (++) and the decrease operator (--) increase or reduce by one the value stored in a variable.

  • The three expressions below should produce exactly the same executable code:

    ++x;
    x+=1;
    x=x+1;
    
  • As a prefix :

    x = 3;
    y = ++x;
    // x contains 4, y contains 4
    
  • As a postfix :

    x = 3;
    y = x++;
    // x contains 4, y contains 3
    

Comma operator (,)

  • Is used to separate two or more expressions that are included where only one expression is expected.

  • When the set of expressions has to be evaluated for a value, only the right-most expression is considered.

  • For example, the following code:

a = (b=3, b+2);
  • Would first assign the value 3 to b, and then assign b+2 to variable a. So, at the end, variable a would contain the value 5 while variable b would contain value 3.